-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: Simple type fixes for ExtensionArray #41255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's not deviate from typing we have elsewhere in the codebase. if you think that is wrong then pls update as well (e.g. Series et all).
pandas/core/arrays/base.py
Outdated
@@ -385,7 +387,7 @@ def __iter__(self): | |||
for i in range(len(self)): | |||
yield self[i] | |||
|
|||
def __contains__(self, item) -> bool | np.bool_: | |||
def __contains__(self, item: Any) -> bool | np.bool_: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we type this with Label elsewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jreback I did a grep and only saw Any
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Label
is for index values, this is an array, so Any
is correct I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Label was an alias for Union[Hashable, None] to workaround a mypy bug that has since been fixed. Now mypy recognizes None as being Hashable.
wrt Any
from https://github.com/python/typeshed/blob/master/CONTRIBUTING.md#incomplete-stubs
Included functions and methods must list all arguments, but the arguments can be left unannotated. Do not use Any to mark unannotated arguments or return values.
from https://github.com/python/typeshed/blob/master/CONTRIBUTING.md#conventions
When adding type hints, avoid using the Any type when possible. Reserve the use of Any for when:
the correct type cannot be expressed in the current type system; and
to avoid Union returns (see above).
Note that Any is not the correct type to use if you want to indicate that some function can accept literally anything: in those cases use object instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on that explanation, it should be object
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've used object
, but had to do a type ignore
when any()
was called on a comparison. I couldn't figure out how to work around that. See latest commit.
thanks @Dr-Irv very nice |
Typing changes for the following methods in
ExtensionArray
__iter__
__contains__
fillna
transpose
ravel
__hash__